<?php
/**
 * 
 *
 * @author EpicDewd
 * @version 1.0
 * @copyright HalpMeh, 11 November, 2010
 * @package 4chan
 **/
class Install
{
	function __construct()
	{
		# Construct Function
	}
	function __destruct()
	{
		# Destruct Function
	}
	public function Done()
	{
		# Stops the script.
		return false;
	}
	public function HTML()
	{
	# Just echos the html.  Used to keep things cleaner.
			echo <<<HTML
			    <div id="main" class="grid_8 alpha">

			        <article class="post">

			            <h2>Contact</h2>

			            <form action="?install" method="post" id="infos">

			                <p>
			                    <input type="text" name="host" id="host" class="grid_3" value="" />
			                    <label for="host">Host</label>
			                </p>

			                <p>
			                    <input type="text" name="user" id="user" class="grid_3" value="" />
			                    <label for="User">User</label>
			                </p>

			                <p>
			                    <input type="text" name="pass" id="pass" class="grid_3" value="" />
			                    <label for="pass">Pass</label>
			                </p>

			                <p>
			                	<input id="name" class="grid_6" cols="50" rows="10" />
								<label for="name">Name</label>
			                </p>

							<!-- This is hidden for normal users -->
			                <div class="hide">
			                    <label>Do not fill out this field</label>
			                    <input name="spam_check" type="text" value="" />
			                </div>

			                <p>
			                	<input type="submit" name="submit" class="grid_2" value="Send Email" />
			                </p>

			                <p class="hide grid_7" id="response"></p>

			            </form>

			            <div class="clear"></div>

			        </article> <!-- end .post -->

			    </div> <!-- end main -->
HTML;
	}
	public function Generate($host, $user, $pass, $name)
	{
		if($writer = @fopen("Config.php", "a+"))
		{
			fwrite($writer, "\n\n\$host = '$host';\n\$user = '$user';\n\$pass = '$pass';\n\$name = '$name';\n\n# File generated by 4chan\n\n?>");
			fclose($writer);
			echo <<<HTML
			<h1>
				Success!
			</h1>
			<h2>
				Install Completed!
			</h1>
			<p>
				You will now be redirected back home
			</p>
			<!-- Redirect Code Goes Here. -->
HTML;
		}
		# If the writing to the file fails.
		else
		{
			echo <<<HTML
		<h2>
			Config File
		</h2>
		<p>
			Unfortunately we were unable to write to your config file (Config.php).  You may chmod it to 777 and re-try or paste this code into the bottom of Config.php.
		</p>
HTML;
	echo "\$host = '$host'; <br />";
	echo "\$user = '$user'; <br />";
	echo "\$pass = '$pass'; <br />";
	echo "\$name = '$name'; <br />";
	echo "?>";

		}
	}
}
?>
